<%@page import="com.epcs.util.EpcsDateTimeUtil"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>

<s:set var="MOST_FOLLOWING_EVENT_LIST"	value="%{#request.MOST_FOLLOWING_EVENT_LIST}" />
<s:set var="FOLLOWING_EVENT_LIST"	value="%{#request.FOLLOWING_EVENT_LIST}" />
<s:set var="NUMBER_OF_FOLLOWING" value="%{#request.NUMBER_OF_FOLLOWING}" />
<s:set var="EMPTY_LIST" value="%{#request.EMPTY_LIST}" />
<s:set var="user_info" value="%{#session.USER_INFO}" />

<s:iterator var="event_iter" value="%{#MOST_FOLLOWING_EVENT_LIST}"
	status="counter">
	<s:iterator var="following_iter" value="%{#FOLLOWING_EVENT_LIST}"
		status="counter1">
		<s:if test="#counter.index == #counter1.index">
			<div class="row deliverEvent panel panel-primary">								
				<div class="row">
					<div class="col-md-9">
						<a	href="PublicEventDetail.do?id=${event_iter.eventId}">
							<span style="font-size: 19"><b> ${event_iter.title}</b></span>
						</a>
					</div>
					
					<div class="col-md-3">
						<s:if test="%{#user_info.username != #event_iter.account.username }">
							<c:if test="${!empty(following_iter) }">
								<input type="button"
									onclick="changeFollowing(${following_iter.followingId},${event_iter.eventId},this)"
									value="Hủy theo dõi" class="btn btn-danger btn-xs"
									style="width: 125px;" />
							</c:if>

							<c:if test="${empty(following_iter) }">
								<input type="button"
									onclick="changeFollowing('',${event_iter.eventId},this)"
									value="Theo dõi" class="btn btn-success btn-xs"
									style="width: 125px;" />
							</c:if>
						</s:if>
							<%
								String datetime = EpcsDateTimeUtil.getCurrentIsoByPattern("yyyy-MM-dd'T'HH:mm:ssZ");
								datetime = EpcsDateTimeUtil.convertToJSPDatetime(datetime);
								request.setAttribute("CURRENT_DATETIME", datetime);
							%>
							<s:set var="currentTime" value="%{#request.CURRENT_DATETIME}" ></s:set>
							<fmt:parseDate value="${event_iter.startTime}" pattern="yyyy-MM-dd'T'HH:mm:ssZ" var="start"/>	
							<fmt:parseDate value="${currentTime}" pattern="yyyy-MM-dd'T'HH:mm:ssZ" var="current"/>	
							<s:set var="now">${current.time}</s:set>
							<s:set var="begin">${start.time}</s:set>
						<s:if test="%{#user_info.username == #event_iter.account.username }">
							<s:if test="%{#now <= #begin}">
								<a href="EventDetail.do?id=${event_iter.eventId}" class="btn btn-warning btn-xs" style="width: 125px;">
									Chỉnh sửa
								</a>
							</s:if>
						</s:if>
					</div>
				
				</div>
				<div class="row">
					<div class="col-md-10">
						<b>Đang có</b>
						<span id="numberOfFollow_${event_iter.eventId}" style="color:#428bca;">
							${NUMBER_OF_FOLLOWING[counter.count - 1]}
						</span> 
						<b>người theo dõi!</b>
					</div>
				</div>
				<div class=" row invisibleLine"></div>
				<div class="row">
					<div class="col-md-3"><b>Người tạo: </b> </div>
					<div class="col-md-7">${event_iter.account.fullname}</div>
				</div>
				<div class="row">
					<div class="col-md-3"><b>Thể loại: </b> </div>
					<div class="col-md-7">
					
						<s:if test="%{#event_iter.eventcategory == ''}">
						Chưa cập nhật
					</s:if>
					<s:else>
							<s:property value="%{#event_iter.eventcategory.eventCategoryName}"/>
					</s:else>
					</div>
				</div>
				<div class="row">
					<div class="col-md-3"><b>Địa điểm: </b> </div>
					<div class="col-md-9"> 
					<s:if test="%{#event_iter.location == ''}">
						Chưa cập nhật
					</s:if>
					<s:else>
						${event_iter.location}
					</s:else>
					</div>
				</div>
				<div class="row">
					<div class="col-md-3"><b>Thời gian diễn ra: </b> </div>
					<div class="col-md-7">
						<fmt:parseDate value="${event_iter.startTime}" pattern="yyyy-MM-dd'T'HH:mm:ssZ" var="start" />
						<fmt:parseDate value="${event_iter.endTime}" pattern="yyyy-MM-dd'T'HH:mm:ssZ" var="stop" />
						<div class="row">
							<div class="col-md-12">
							Từ 
							<s:if test="%{#event_iter.isAllDayEvent}">
								<fmt:formatDate value="${start}" pattern="'ngày' dd 'tháng' MM 'năm' yyyy" />
							</s:if>
							<s:else>
								<fmt:formatDate value="${start}" 
								pattern="HH 'giờ' mm 'phút, ngày' dd 'tháng' MM 'năm' yyyy" />
							</s:else>
							</div>
						</div>
						<div class="row">
							<div class="col-md-12">
							Đến 
							<s:if test="%{#event_iter.isAllDayEvent}">
								<fmt:formatDate value="${stop}" pattern="'ngày' dd 'tháng' MM 'năm' yyyy" />
							</s:if>
							<s:else>
								<fmt:formatDate value="${stop}" 
								pattern="HH 'giờ' mm 'phút, ngày' dd 'tháng' MM 'năm' yyyy" />
							</s:else>
							</div>
						</div>
					</div>	
				</div>
				<div class="row">
					<div class='deliverLine'></div>
					<div class="col-md-11"><b>Mô tả: </b> 
						<s:if test="%{#event_iter.description != ''}">${event_iter.description}</s:if>
						<s:else>Không có mô tả!</s:else>
					</div>
				</div>
			</div>			
		</s:if>
	</s:iterator>
</s:iterator>
	
<s:if test="%{#EMPTY_LIST == true}">
empty
</s:if>